<template>
  <div>
    <!-- 登录页面 -->
    <!-- 标题栏 -->
    <van-nav-bar 
      title="注册"  
      left-text="返回登录"
      right-text="其他方式登录"
      left-arrow >
    </van-nav-bar>
    <!-- 表单 -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="email"
        type="email"
        name="邮箱"
        label="邮箱"
        placeholder="请输入邮箱"
        :rules="[{ required: true, message: '请填写邮箱' }]"
      />
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="请输入用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
      v-model="repassword"
        type="password"
        name="确认密码"
        label="确认密码"
        placeholder="请再次输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <!-- 按钮 -->
      <div style="margin: 16px;">
        <van-button round block color="#fa7e3e" type="info" native-type="submit" @click="register">免费注册</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  data() {
      return {
        email:'',
        username: '',
        password: '',
        repassword:'',
      };
    },
    methods: {
      onSubmit(values) {
        console.log('submit', values);
      },
      register(){
      let params = `email=${this.email}&uname=${this.username}&upwd=${this.password}`
      let url = 'http://127.0.0.1:8808/v1/xsps/reg'
      this.axios.post(url,params)
      .then(res=>{
        if(res.data.code == 200){
          this.$toast.success(res.data.msg);
          this.$router.push({path:'/login'})
        }
      })
    }
    },
}
</script>

<style>

</style>